package org.sherlock.ui.gui.components;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JPanel;

import org.sherlock.downloader.Download;

public class JDownloadPanel extends JPanel {

	private Download download;
	private JDownloadPanelCenter centerPanel;

	private static final long serialVersionUID = -5214242070570421299L;

	public JDownloadPanel(Download download) {
		this.download = download;
		setLayout(new BorderLayout());
		add(getCenterPanel(), BorderLayout.CENTER);
		setMaximumSize(new Dimension(0,200));
		setPreferredSize(new Dimension(0,200));
	}

	private JPanel getCenterPanel() {
		if (centerPanel == null)
			centerPanel = new JDownloadPanelCenter(download.getFileName(), download.getHumanSize(), download.getHumanDownloaded(), (int) download.getProgress());
		return centerPanel;
	}

	public Download getDownload() {
		return download;
	}

	public void updateDownload() {
		centerPanel.updateData(download.getHumanDownloaded(), (int) download.getProgress());
	}

}
